# Haifa University WiFi - stay online
# HTTP version
# Author: Ofir Cohen

# Dependencies
use Modern::Perl;
use LWP::UserAgent;
use HTTP::Request::Common qw(POST);
use constant ACLASS => "132";  # A class of the IP assigned by DHCP

# getip()
# -------
# finds if user has established Wi-Fi connection already
# returns: -1 - if no valid ip yet
#		        otherwise it returns the ip address            
sub getip {
	local $_ = `ipconfig`;
	return (/(?<ipaddr>${\(ACLASS)}\.\d{0,3}\.\d{0,3}\.\d{0,3})/) ? $+{ipaddr} : "-1";
}


# variables definition
my ($user,$pass,$url,$ua,$reqstr,$request,$content);

# login details
$user = "ofir";
$pass = "1111";

# other variables
$ua = LWP::UserAgent->new; 
$ua->agent("Mozilla 8.0 blah...");
$url = 'https://localhost/xampp/1.pl';
$reqstr = (POST $url, 
["user" => $user, 
"pass" => $pass]);


# send request
$request = $ua->request($reqstr);
$content = $request->content; 


say (($content =~ /^correct\b/gm) ? "success." : "failed");

#print "Content-type: text/html\n\n"; 
#print $content; 
exit;